package com.cloud.freeflow.api.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.cloud.freeflow.api.entity.ProcActFilter;
import com.cloud.freeflow.api.entity.ProcPart;
import com.cloud.freeflow.common.utils.BaseMapperHelper;

public interface ProcActFilterMapper extends BaseMapperHelper<ProcActFilter> {
	
	@Select("SELECT c.part_id, c.part_name, c.part_type, if(b.part_id is null, 0, b.part_id) as relation_id FROM proc_act_part a "
			+ "LEFT JOIN proc_act_filter b ON a.part_id = b.part_id and b.act_def_id = #{actDefId} LEFT JOIN proc_part c on a.part_id = c.part_id "
			+ "WHERE a.act_def_id = #{actDefId} and c.proc_def_id = #{procDefId} ORDER BY relation_id DESC, part_id ASC")
	@Results({ @Result(property = "partId", column = "part_id", javaType = Long.class),
			@Result(property = "partName", column = "part_name", javaType = String.class),
			@Result(property = "partType", column = "part_type", javaType = String.class),
			@Result(property = "relationId", column = "relation_id", javaType = Long.class) })
	List<ProcPart> listActFilters(@Param("procDefId") Long procDefId, @Param("actDefId") Long actDefId);
}